module.exports = function (appVersion) {
    require('Global');
    require('AppCall')();

    CONFIG.appVersion = appVersion;

    window.LinkUtil = {};
    window.LinkHttp = {};

    LinkHttp.NewLink = function (url, param) {
        var target = null;
        var linker = cc.Linker(url, param);
        return {
            setTarget(value) {
                target = value;
                return this;
            },
            autoLogin(value) {
                linker.autoLogin(value);
                return this;
            },
            showLoading(value) {
                linker.showLoading(value);
                return this;
            },
            showMessage(value) {
                linker.showMessage(value);
                return this;
            },
            request(OKcbk, NOcbk) {
                linker.request(data => {
                    if (target) OKcbk && OKcbk.call(target, data);
                    else OKcbk && OKcbk(data);
                }, (error, code) => {
                    if (target) NOcbk && NOcbk.call(target, error, code);
                    else NOcbk && NOcbk(error, code);
                });
                return this;
            }
        };
    }

    LinkUtil.RequestToken = function (game, cbk) {
        cc.GameProxy.getAccessToken(game, cbk);
    }

    LinkUtil.gameLogin = function () {
        cc.GameProxy.callLogin();
    }

    LinkUtil.backHome = function () {
        cc.GameProxy.backHome();
    }

    LinkUtil.openShop = function (openCbk, closeCbk) {
        cc.GameProxy.openShop(openCbk, closeCbk);
    }

    LinkUtil.EventPoint = function (type, cbk) {
        cc.GameProxy.buryingPoint(type, cbk);
    }

    LinkUtil.PlayerInfo = function (OKcbk) {
        cc.GameProxy.getUserInfo(OKcbk);
    }

    LinkUtil.formatCount = function (count) {
        return cc.Global.formatNumber(count);
    }

    LinkUtil.onBetNotEnough = function (cbk) {
        if(LINK.isGuestLogin) {
            cc.Popup.show('public/BindInfoPop', null, cbk)
        } else {
            cbk && cbk();
        }
    }
}